<extend name="./Public/base" />
<block name="title">个人中心</block>
<block name="head">
    <load href="__PUBLIC__/Css/info.css"/>
</block>

<block name="header">
    <include file="Application/Home/View/Public/header_stu.html"/>
</block>
<block name="main">
    <div class="container" id="container">
        <div class="row">
            <div class="col-md-offset-2 col-md-8 margin-bottom-10">
                <div class="alert alert-danger hidden" role="alert"></div>
                <div class="alert alert-success hidden" role="alert"></div>
                <nav class="nav nav-pills">
                    <li><a href="__MODULE__/StuSettings/info">基本资料</a></li>
                    <li class="active"><a href="__MODULE__/StuSettings/change_pwd">密码管理</a></li>
                </nav>
            </div>
        </div>
        <div class="row">
            <div class="col-md-offset-2 col-md-8">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-11">
                                <ul class="list-inline">
                                    <li><b>旧密码:</b></li>
                                    <li><input type="password" class="form-control" id="old_pwd" placeholder="请输入旧密码"/></li>
                                </ul>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-11">
                                <ul class="list-inline">
                                    <li><label>新密码:</label></li>
                                    <li><input type="password" class="form-control" id="new_pwd" placeholder="请输入新密码"/></li>
                                </ul>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-11">
                                <ul class="list-inline">
                                    <li><label>确定新密码:</label></li>
                                    <li><input type="password" class="form-control" id="new_pwd2" placeholder="请再次输入新密码"/></li>
                                </ul>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-11">
                                <ul class="list-inline">
                                    <button class="btn btn-primary" id="save">保存</button>
                                </ul>
                                <input type="hidden" id="url" value="__MODULE__"/>
                            </div>
                </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(function(){
            var save = $("#save");
            var old = $("#old_pwd");
            var new1 = $("#new_pwd");
            var new2 = $("#new_pwd2");

            save.click(function(){
                save.blur();
                var old_pwd = old.val();
                var new_pwd = new1.val();
                var new_pwd2 = new2.val();
                if(old_pwd!=""&&new_pwd!=""&&new_pwd2!=""){
                    if(new_pwd == new_pwd2){
                        postData = {old_pwd:CryptoJS.MD5(old_pwd).toString(),new_pwd:CryptoJS.MD5(new_pwd).toString()};
                        postApi("__MODULE__/StuSettings/update_stu_pwd", postData, function(err, data) {
                            if (err) {
                                old.val("");
                                old.focus();
                                showError(err.message);
                            } else {
                                old.val(""); //清空输入框
                                new1.val("");
                                new2.val("");
                                showSuccess(data.message); //提示修改成功
                            }
                        });
                    }
                    else{
                        //新密码不相等处理
                        showError("两次密码不一样！");
                        new1.val("");
                        new2.val("");
                        new1.focus();
                    }
                }
                else{
                    if(old_pwd==""){
                        showError("请输入旧密码！");
                        old.focus();
                    }
                    else if(new_pwd==""){
                        showError("请输入新密码！");
                        new1.focus();
                    }
                    else{
                        showError("请再次输入新密码！");
                        new2.focus();
                    }
                }
            });
        });
    </script>
</block>